package com.xixilala.video

import android.content.Context
import android.view.ViewGroup
import android.widget.Button
import androidx.recyclerview.widget.RecyclerView

class RvAdapter(private val context: Context, private val callback: (position: Int) -> Unit):RecyclerView.Adapter<RvAdapter.Holder>() {
    inner class Holder( val view: Button):RecyclerView.ViewHolder(view)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        return Holder(Button(context).apply {
            layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
        })
    }

    override fun onBindViewHolder(holder: Holder, position: Int) {
        holder.view.text = data[position].third

        holder.view.setOnClickListener {
            callback.invoke(position)
        }
    }

    override fun getItemCount(): Int {
        return data.size
    }
}
